{include="header"}

<script type="text/javascript">
   function full_regiva(id)
   {
      $.ajax({
         type: 'POST',
         url: '{$fsc->url()}',
         dataType: 'html',
         data: 'idregiva='+id,
         success: function(datos) {
            $("#modal_full_regiva2").html(datos);
            $("#modal_full_regiva").modal('show');
         }
      });
   }
   function completar_regiva()
   {
      document.f_nueva_regiva.proceso.value = 'comprobar';
      $.ajax({
         type: 'POST',
         url: '{$fsc->url()}',
         dataType: 'html',
         data: $("form[name=f_nueva_regiva]").serialize(),
         success: function(datos) {
            $("#lineas_regiva").html(datos);
         }
      });
   }
   function guardar_regiva()
   {
      document.f_nueva_regiva.proceso.value = 'guardar';
      document.f_nueva_regiva.submit();
   }
   $(document).ready(function() {
      $("#b_nueva_regiva").click(function(event) {
         event.preventDefault();
         $("#lineas_regiva").html('');
         $("#modal_nueva_regiva").modal('show');
      });
   });
</script>

<form class="form-horizontal" role="form" name="f_nueva_regiva" action="{$fsc->url()}" method="post">
   <input type="hidden" name="proceso" value=""/>
   <div class="modal fade" id="modal_nueva_regiva">
      <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h4 class="modal-title">Nueva regularización de IVA</h4>
            </div>
            <div class="modal-body">
               <div class="form-group">
                  <label for="periodo" class="col-lg-2 col-md-2 col-sm-2 control-label">Período</label>
                  <div class="col-lg-10 col-md-10 col-sm-10">
                      <select name="periodo" class="form-control">
                         {if condition="$fsc->periodo=='T1'"}<option selected="selected">T1</option>{else}<option>T1</option>{/if}
                         {if condition="$fsc->periodo=='T2'"}<option selected="selected">T2</option>{else}<option>T2</option>{/if}
                         {if condition="$fsc->periodo=='T3'"}<option selected="selected">T3</option>{else}<option>T3</option>{/if}
                         {if condition="$fsc->periodo=='T4'"}<option selected="selected">T4</option>{else}<option>T4</option>{/if}
                      </select>
                   </div>
               </div>
               <div class="form-group">
                  <label for="desde" class="col-lg-2 col-md-2 col-sm-2 control-label">Desde</label>
                  <div class="col-lg-10 col-md-10 col-sm-10">
                     <input class="form-control datepicker" type="text" name="desde" value="{$fsc->fecha_desde}"/>
                  </div>
               </div>
               <div class="form-group">
                  <label for="hasta" class="col-lg-2 col-md-2 col-sm-2 control-label">Hasta</label>
                  <div class="col-lg-10 col-md-10 col-sm-10">
                     <input class="form-control datepicker" type="text" name="hasta" value="{$fsc->fecha_hasta}"/>
                  </div>
               </div>
            </div>
            <div class="modal-footer">
               <button class="btn btn-sm btn-default" type="button" onclick="completar_regiva()">
                   <span class="glyphicon glyphicon-play"></span> &nbsp; Completar
                </button>
            </div>
            <div id="lineas_regiva"></div>
         </div>
      </div>
   </div>
</form>

<div class="modal fade" id="modal_full_regiva">
   <div class="modal-dialog">
      <div class="modal-content" id="modal_full_regiva2"></div>
   </div>
</div>

<div class="table-responsive">
   <table class="table table-hover">
      <thead>
         <tr>
            <th class="text-left">Periodo@Ejercicio</th>
            <th class="text-left">Fecha del asiento</th>
            <th class="text-left">Fecha de inicio</th>
            <th class="text-right">Fecha de fin</th>
         </tr>
      </thead>
      {loop="$fsc->regiva->all()"}
      <tr>
         <td>
            <a href="#" onclick="full_regiva('{$value->idregiva}')">
               {$value->periodo}@{$value->codejercicio}
            </a>
         </td>
         <td>{$value->fechaasiento}</td>
         <td>{$value->fechainicio}</td>
         <td class="text-right">{$value->fechafin}</td>
      </tr>
      {else}
      <tr class="bg-warning">
         <td colspan="4">Sin resultados. Pulsa el botón <b>Nueva</b> para hacer una regularización de IVA.</td>
      </tr>
      {/loop}
   </table>
</div>

{include="footer"}